//
//  HeaderView.m
//  YuanyangJinlou
//
//  Created by mac004 on 2016/12/29.
//  Copyright © 2016年 suli19910309@qq.com. All rights reserved.
//

#import "HeaderView.h"
#import "EScrollerView.h"
@interface HeaderView()<EScrollerViewDelegate>
{
    EScrollerView*_escrollView;
}
@end
@implementation HeaderView
-(instancetype)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        [self creatUI];
    }return self;
}
-(void)creatUI{
    self.backgroundColor=[UIColor whiteColor];
    if (!_escrollView) {
        _escrollView = [[EScrollerView alloc]initWithFrameRect:CGRectMake(0, 0, self.width, 140*PER_HEIGHT) ImageArray:@[] TitleArray:@[] changPic:YES];
        _escrollView.delegate = self;
    }
    [self addSubview:_escrollView];
    
    //学习专区
    UIView*studyView=[[UIView alloc]initWithFrame:CGRectMake(0, 140*PER_HEIGHT, self.width, 200*PER_HEIGHT)];
    studyView.backgroundColor=[UIColor cyanColor];
    [self addSubview:studyView];
    NSArray*imageArr1=@[@"ico_xuexibeikao",@"ico_yuekao",@"ico_zhuanye",@"ico_mouni"];
    NSArray*imageArr2=@[@"ico_paihang",@"ico_guize",@"ico_quwei",@"ico_gonggao"];
    NSArray*title1=@[@"学习备考",@"月考",@"专业考试",@"模拟考试"];
    NSArray*title2=@[@"名人堂",@"积分规则",@"趣味答题",@"公告"];
    //第一批按钮
    for (int i = 0; i<4; i++) {
        UIButton*btn=[MyControl createButtonWithFrame:CGRectMake(29*PER_WIDTH+i*89*PER_WIDTH, 24*PERCEN_HEIGHT, 46*PER_WIDTH, 68*PER_WIDTH) ImageName:@"" Target:self Action:@selector(topBtn:) Title:@""];
        btn.tag=100+i;
        [studyView addSubview:btn];
        
        UIImageView*img=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 46*PER_WIDTH, 46*PER_WIDTH)];
        img.image=[UIImage imageNamed:imageArr1[i]];
        [btn addSubview:img];
        
        UILabel*lab=[MyControl createLabelWithFrame:CGRectMake(0, img.bottom+9*PER_HEIGHT, img.width, 13*PER_HEIGHT) Font:11.5 Text:title1[i]];
        lab.textColor=UIColorFromHex(0x555555);
        lab.textAlignment=NSTextAlignmentCenter;
        [btn addSubview:lab];
        
    }
    //第二批按钮
    for (int i = 0; i<4; i++) {
        UIButton*btn=[MyControl createButtonWithFrame:CGRectMake(29*PER_WIDTH+i*89*PER_WIDTH, 200*PERCEN_HEIGHT, 46*PER_WIDTH, 68*PER_WIDTH) ImageName:@"" Target:self Action:@selector(topBtn:) Title:@""];
        btn.tag=103+i;
        [studyView addSubview:btn];
        
        UIImageView*img=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 46*PER_WIDTH, 46*PER_WIDTH)];
        img.image=[UIImage imageNamed:imageArr2[i]];
        [btn addSubview:img];
        
        UILabel*lab=[MyControl createLabelWithFrame:CGRectMake(0, img.bottom+9*PER_HEIGHT, img.width, 13*PER_HEIGHT) Font:11.5 Text:title2[i]];
        lab.textColor=UIColorFromHex(0x555555);
        lab.textAlignment=NSTextAlignmentCenter;
        [btn addSubview:lab];
        
    }

}

-(void)topBtn:(UIButton*)sender{
    if (_delegate&&[_delegate respondsToSelector:@selector(clickBtn:)]) {
        [_delegate clickBtn:sender];
    }
}
@end
